package com.love.cloud.common.core.util;

import org.modelmapper.ModelMapper;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

/**
 * @author hongdongqu
 * @version 1.0
 */
@Component
public class ModelMapperUtils {
    @Resource
    private ModelMapper modelMapper;

    public ModelMapper getModelMapper(){
        return this.modelMapper;
    }

    /**
     * 转化新的对象list
     * @param oldModelList
     * @param destinationType
     * @return
     */
    public List toNewModelList(List oldModelList, Type destinationType){
        List newModelList=new ArrayList();
        for (Object object:oldModelList) {
            Object newObject=modelMapper.map(object, destinationType);
            newModelList.add(newObject);
        }
        return newModelList;
    }
}
